﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MongoDB.Bson;

using MongoDB.Bson.Serialization;
using YmtAuth.Domain.Model.YmatouUser.Event;

namespace YmtUserAuth.DataImport2
{
    public class FieldToUserBills
    {
        public static IEnumerable<Dictionary<string, object>> Adapter(IEnumerable<string[]> fields)
        {
            var list = new List<Dictionary<string, object>>();
            foreach (var item in fields)
            {
                if (item.Length < 6)
                {
                    Console.WriteLine("sss");
                    continue;
                }
                try
                {
                    if (item[1].ToLower().EndsWith(".qqcb")) continue;

                    var iUserId = Convert.ToInt32(item[0]);
                    var sLoginId = item[1].Replace("\t", "").Replace("\r\n", "").Trim().ToLower();
                    var sPassword = item[2];
                    var sTradingPassword = (item[3].Trim() == "NULL" || string.IsNullOrEmpty(item[3]) || string.IsNullOrEmpty(item[3].Trim())) ? null : item[3].Trim();
                    var sLoginMail = (item[4].Trim() == "NULL" || string.IsNullOrEmpty(item[4]) || string.IsNullOrEmpty(item[4].Trim()) || item[4].ToLower() == ".deleted") ? null : item[4].Trim().ToLower();
                    var sMobile = (item[5].Trim() == "NULL" || string.IsNullOrEmpty(item[5]) || string.IsNullOrEmpty(item[5].Trim())) ? null : item[5].Trim();
                    var bLocked = item[6];
                    if (string.IsNullOrEmpty(sLoginId) || string.IsNullOrEmpty(sPassword)) continue;
                    var uData = new Dictionary<string, object> 
                    {
                   
                        {"sPassword",sPassword},//              
                        {"iUserId",iUserId},
                        {"sLoginId",sLoginId},
                        {"sMobile",sMobile},
                        {"sTradingPassword",sTradingPassword},
                        {"sLoginEmail",sLoginMail},
                        {"sDataImport","import"}, //标记为数据导入
                        {"bLocked",bLocked}
                    };
                    list.Add(uData);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(item.ToJson());
                    throw;
                }
            }
            return list;
        }

        public static IEnumerable<LoginIdUpdateEvent> AdapterUserBillsUpEvent(IEnumerable<string[]> fields)
        {
            var list = new List<LoginIdUpdateEvent>();
            foreach (var item in fields)
            {
                if (item.Length < 6) continue;
                var loginIdUpdateEvent = new LoginIdUpdateEvent(item[2], Convert.ToInt32(item[1]), item[4], Ymatou.User.Dto.Auth.UserSource.App);
                list.Add(loginIdUpdateEvent);
            }

            return list;
        }

        public static IEnumerable<UserMobile> AdapterUserMobile(IEnumerable<string[]> fields)
        {
            var list = new List<UserMobile>();
            foreach (var item in fields)
            {
                if (item.Length < 2) continue;
                var um = new UserMobile { UserId = Convert.ToInt32(item[0]), Mobile = item[1].Trim() };
                list.Add(um);
            }
            return list;
        }
    }
}
